package net.chengp.ms.auth.exception;

import java.io.IOException;

import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

import net.chengp.ms.commons.result.R;
import net.chengp.ms.commons.result.Result;

public class CustomOauthExceptionSerializer extends StdSerializer<CustomOauthException> {

	private static final long serialVersionUID = -7219642823005407607L;

	public CustomOauthExceptionSerializer() {
		super(CustomOauthException.class);
	}

	@Override
	public void serialize(CustomOauthException value, JsonGenerator gen, SerializerProvider provider)
			throws IOException {
		Result<?> result = R.error(value.getHttpErrorCode(), value.getMessage());
		gen.writeBinary(JSONObject.toJSONBytes(result));
		gen.writeEndObject();
	}
}